package com.newjiabo.applet.controller;

import com.newjiabo.applet.modules.service.CashierService;
import com.newjiabo.applet.modules.service.MemberService;
import com.newjiabo.common.utils.SecurityUtils;
import com.newjiabo.ski.domain.SkiMemberBodyInfo;
import com.newjiabo.ski.domain.dto.WechatMPLoginParams;
import com.newjiabo.applet.modules.service.ConnectService;
import com.newjiabo.common.core.domain.AjaxResult;
import com.newjiabo.ski.service.ISkiMemberBodyInfoService;
import com.newjiabo.ski.service.ISkiMemberService;
import com.newjiabo.ski.service.MediaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * {小程序登录 退出等接口}
 *
 * @author CaoMengHui.
 * @version 1.0
 * @since 2023/9/15 9:13
 */
@RestController
@RequestMapping(value = "/applet/miniProgram")
@Api(tags = "小程序;登录/注册/个人信息接口")
public class MiniProgramSystemController {

    @Resource
    private ConnectService connectService;
    @Resource
    private MemberService memberService;
    @Resource
    private ISkiMemberService skiMemberService;
    @Resource
    private ISkiMemberBodyInfoService memberBodyInfoService;
    @Resource
    private MediaService mediaService;


    @GetMapping(value = "/auto-login")
    @ApiOperation(value = "小程序自动登录")
    public AjaxResult autoLogin(@RequestHeader String uuid, WechatMPLoginParams params) {
        params.setUuid(uuid);
        return AjaxResult.success(connectService.miniProgramAutoLogin(params));
    }

    @PostMapping(value = "/registerImageInfo")
    @ApiOperation(value = "注册图片信息")
    public AjaxResult registerImageInfo(@RequestBody @Validated SkiMemberBodyInfo skiMemberBodyInfo){
        return AjaxResult.success(memberBodyInfoService.registerImageInfo(skiMemberBodyInfo));
    }

    @ApiOperation(value = "刷新token")
    @GetMapping("/refresh/{refreshToken}")
    public AjaxResult refreshToken(@NotNull(message = "刷新token不能为空") @PathVariable String refreshToken) {
        return AjaxResult.success(this.memberService.refreshToken(refreshToken));
    }

    @ApiOperation(value = "获取小程序用户信息")
    @GetMapping("/getMemberInfo")
    public AjaxResult getMemberInfo(){
        String memberId = SecurityUtils.getLoginUser().getMemberId();
        return AjaxResult.success(skiMemberService.selectSkiMemberById(memberId));
    }
    @ApiOperation(value = "查询注册状态信息")
    @GetMapping("/getRegisterInfo/{snowFieldId}")
    public AjaxResult getRegisterInfo(@PathVariable String snowFieldId){
        return AjaxResult.success(mediaService.getRegisterInfo(snowFieldId));
    }

}
